<template>
  <div>
    <!-- 搜索框 -->
    <TopFilter :list="topFilterList" :cols="1" :collapse="false" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>

    <!-- 工单信息 -->
    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'rows'"
      :height="'350'"
      :selectionType="'single'"
      columnsRef="FDkhtsXzgdGdxxTable"
      :onRowSelectChange="arr => (this.choose = arr)"
      :onColumnsChange="columns => (this.columns = columns)"
    >
    </FilterTable>
    <div style="text-align:center">
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="reqFD">确 定</el-button>
        <el-button type="primary" @click="cancleFd">取 消</el-button>
      </span>
    </div>
  </div>
</template>
<script>
import { mapState } from 'vuex';
import { dictionary } from '@/utils/dictMixin';
import {
  getFdOrder
} from '@/api/customerRepair/customerComplaint/customerComplaintMng';
import dictCode from '@/utils/dictCode';
import { searchRoleByCode } from '@/api/common/empSelect/index';

export default {
  name: 'ChooseFD',
  components: {},
  mixins: [dictionary],
  props: ['vinData'],
  data() {
    this.BaseTable = null;
    return {
      topFilterList: this.createTopFilterList(),
      fetchApi: getFdOrder, // 获取工单表格接口
      fetchParams: { xhrAbort: true }, // 获取工单表格参数
      columns: this.createTableColumns(), // 工单信息表格列
      choose: [] // 选中的工单
    };
  },

  created() {
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
    this.setDefultCondition(this.vinData);

  },
  methods: {
    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'vin',
          disabled: true,
          placeholder: 'VIN'
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          align: 'center',
          width: 70,
          fixed: 'left',
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: 'FD工单号',
          dataIndex: 'VBELNM',
          showOverflowTooltip: true,
          sorter: true
        }
      ];
    },
    setDefultCondition(vinData){
      this.topFilterList.find(item => item.fieldName === 'vin').initialValue = this.vinData.vin;
      this.fetchParams = Object.assign({}, {vin:this.vinData.vin}, { xhrAbort: false });
    },

    // 搜索
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val, { xhrAbort: false });
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    // 取消
    cancleFd() {
      this.$emit('closeFdDia');
    },
    // 确定选择工单
    reqFD() {
      if (this.choose.length === 0) {
        this.$message.error('请选择一个FD工单');
        return;
      }
      this.$emit('reqFD', this.choose[0]);
    }
  }
};
</script>
